package com.bonc.rms.controller.tms;

import java.util.Calendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.bonc.rms.service.tms.IEntryLeaveService;

@Controller
@RequestMapping(value = "/entryLeaveController")
public class EntryLeaveController {

	@Autowired
	IEntryLeaveService entryLeaveService;
	
	/**
	 * 入职率/离职率
	 * 
	 * @param departmentId
	 * @param startMonth 以"-"分割年月
	 * @param endMonth 以"-"分割年月
	 * @return
	 */
	@RequestMapping(value = "/entryLeave")
	@ResponseBody
	public String getEntryLeaveRate(
			@RequestParam(value = "departmentId") Integer departmentId, 
			@RequestParam(value = "startTime") String startMonth, 
			@RequestParam(value = "endTime") String endMonth
			) {
		
		if( "".equals(startMonth) || "".equals(endMonth)) {
			String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
			startMonth = year + "-01";
			endMonth = year + "-12";
		}
		
		return JSON.toJSONString(entryLeaveService.getEntryLeaveData(departmentId, startMonth, endMonth));
	}
	
}
